package com.example.spring_seatreservation.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.spring_seatreservation.Bean.R;
import com.example.spring_seatreservation.entity.SeminarRoom;
import com.example.spring_seatreservation.mapper.SeminarRoomMapper;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping("/seminarRoom")
@AllArgsConstructor
public class SeminarRoomController {

    private final SeminarRoomMapper seminarRoomMapper;

    @GetMapping("getSeminarRoomList")
    public List<SeminarRoom> getSeminarRoomList(){
        return seminarRoomMapper.getSeminarRoom();
    }

    @PostMapping("submit")
    public Map<String, Object> submit(@RequestBody SeminarRoom seminarRoom){
        if (Objects.isNull(seminarRoom.getId())) {
            seminarRoomMapper.insert(seminarRoom);
        } else {
            seminarRoomMapper.updateById(seminarRoom);
        }
        return new R().ok().builder();
    }

    @PostMapping("delRoom")
    public Map<String, Object> delRoom(@RequestBody SeminarRoom seminarRoom){
        seminarRoomMapper.deleteById(seminarRoom.getId());
        return new R().ok().builder();
    }

    @GetMapping("getSeminarRoomListByFloorId")
    public List<SeminarRoom> getSeminarRoomListByFloorId(Long floorId){
        LambdaQueryWrapper<SeminarRoom> lambdaQueryWrapper = Wrappers.<SeminarRoom>lambdaQuery().
                eq(SeminarRoom::getFloorId,floorId);
        return seminarRoomMapper.selectList(lambdaQueryWrapper);
    }
}
